package com.naizhuai.ui.components;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.naizhuai.R;
import com.naizhuai.util.ConstantsState;

/**
 * @author：lichenxi
 * @date 2018/6/11 15
 * email：525603977@qq.com
 * Fighting
 */
public class DialogSureCancel extends Dialog {
    private TextView mTvContent;
    private TextView mTvSure;
    private TextView mTvCancel;
    private TextView mTvTitle;
    private Context mContext;

    public void setTitle(String title) {
        mTvTitle.setText(title);
    }

    public TextView getIv_logo() {
        return mTvTitle;
    }

    public void setContent(String content) {
        this.mTvContent.setText(content);
    }

    public TextView getTvContent() {
        return mTvContent;
    }

    public void setSure(String strSure) {
        this.mTvSure.setText(strSure);
    }

    public TextView getTvSure() {
        return mTvSure;
    }

    public void setCancel(String strCancel) {
        this.mTvCancel.setText(strCancel);
    }

    public TextView getTvCancel() {
        return mTvCancel;
    }

    private WindowManager.LayoutParams mLayoutParams;
    public DialogSureCancel(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public DialogSureCancel(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    public DialogSureCancel(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView(context);
    }

     private void initView(Context context) {
        initBackBround(context);
        View dialog_view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_sure_false, null);
        mTvSure =  dialog_view.findViewById(R.id.tv_sure);
        mTvCancel = dialog_view.findViewById(R.id.tv_cancel);
        mTvContent =dialog_view.findViewById(R.id.tv_content);
        mTvContent.setTextIsSelectable(true);
        mTvTitle = dialog_view.findViewById(R.id.tv_title);
        setContentView(dialog_view);
    }

    private void initBackBround(Context context) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setBackgroundDrawableResource(R.drawable.transparent_bg);
        mContext = context;
        Window window = this.getWindow();
        mLayoutParams = window.getAttributes();
        mLayoutParams.alpha = 1f;
        window.setAttributes(mLayoutParams);
        if (mLayoutParams != null) {
            mLayoutParams.height = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
            mLayoutParams.gravity = Gravity.CENTER;
        }
    }
}
